home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / replace_link < prev    next >
Encoding:
Korn shell script  |  1995-03-24  |  1.1 KB  |  36 lines

  1. #! /bin/ksh
  2. USAGE='USAGE: replace_link  FILE_PATH DEST_PATH
  3.    FILE_PATH should be a link whose ultimate desitnation is DEST_PATH.
  4.    Replace FILE_PATH with a link to DEST_PATH.
  5. '
  6. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  7.  
  8. # Process parameters
  9.    if [ $# -ne 2 ]
  10.    then
  11.       echo "$USAGE" >&2
  12.       echo "Expected 2 arguments, got $#" >&2
  13.       exit 1
  14.    fi
  15.    FILE_PATH="$1"; shift
  16.    DEST_PATH="$1"; shift
  17.    ##echo "replace_link: At 1, DEST_PATH is $DEST_PATH"
  18.    if [ ! -L "$FILE_PATH" ]
  19.    then
  20.       echo "$USAGE" >&2
  21.       echo "FILE_PATH, $FILE_PATH , is not a link." >&2
  22.       exit 1
  23.    fi
  24.    ##echo "replace_link: At 1, DEST_PATH is $DEST_PATH"
  25.    ##echo "replace_link: At 1, FILE_PATH is $FILE_PATH"
  26.    ##echo "replace_link: At 2, DEST_PATH is $DEST_PATH"
  27.    # If DEST_PATH starts with the directory of $FILE, then use a 
  28.    # relative link
  29.    FRONT="$(dirname "$FILE_PATH")/"
  30.    eval "DEST_PATH=\"${DEST_PATH#${FRONT}}\""
  31.    ##echo "replace_link: At 3, DEST_PATH is $DEST_PATH"
  32.    echo "replace_link: Replace $FILE_PATH with $DEST_PATH"
  33.    rm "$FILE_PATH"
  34.    ln -s "$DEST_PATH" "$FILE_PATH"
  35.    exit 0
  36.